package main

import (
	"flag"
	"fmt"
	"log"

	"hello/internal/config"
	"hello/internal/handler"
	"hello/internal/svc"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "etc/hello-api.yaml", "the config file")

func main() {
	flag.Parse()

	// 1. 加载配置文件
	var c config.Config
	conf.MustLoad(*configFile, &c)
	log.Printf("load config file Prop Address: %s\n", c.Address)
	log.Printf("load config file Prop AppName: %s\n", c.AppName)

	// RestConf是默认的配置, 可以不用写
	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()

	// 2. 注入mysql, redis等配置
	ctx := svc.NewServiceContext(c)
	// 3. 注册路由
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}
